<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
    <title>美策平台</title>
    <link rel="icon" type="image/png" href="/img/icon.png">
    <link rel="stylesheet" type="text/css" href="../datepicker/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" href="../css/app.css">
    <link rel="stylesheet" type="text/css" href="../css/index.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="/h5/js/all.js"></script>

</head>
<style>
    .facMenuActive{
        background-color: #3B7DF2 ! important;
        color: #fff ! important;
    }
    .none{
        display: none;
    }
    .nullCetner{
        text-align: center;
        position: absolute;
        top: 6.666667rem;
        transform: translate(-50%, -50%);
        left: 50%;
        color: #c3c3c3;
    }
</style>
<body>
<!--
    制作者：九哥
    页面：找工厂页面
    时间：2019-03-01
-->





<!----------找工厂页面---------->
<div id="factoryPage"><!--此ID页面切换用-->
    <div id="factoryTitle">
        <b>找工厂</b>
        <img src="../images/return.png" onclick="window.location.href = '../index.html'">
    </div>
    <!--div id="factoryPpt">
        <img src="/uploads/20190227/companyppt.png">
    </div-->
    <div id="factoryDetail">
        <div style="height:10px;"></div>
        <div class="menu">
            <p class="letTitle">推荐</p>
            <div class="facMore">更多厂</div>
        </div>
        <div class="list">
        </div>
    </div>
</div>
<!----------找工厂页面---------->





<!----------错误提示---------->
<div id="errMsg"></div>
<!----------错误提示---------->
</body>
<script type="text/javascript" src="../js/indexPageChange.js"></script>
<script type="text/javascript" src="../js/index.js"></script>
<script>
        $(function() {
            $.ajax({
            url: '/api/home/factory/cate',
            type:'get',
            dataType:'json',
            contentType: "application/json",
            // async: false,
            success: function (result) {
                if (result.code === 200) {
                    var data = result.data;
                    console.log(data)
                    var div = '';
                    for (let i = 0; i < data.length; i++) {
                        if (i === 0) { 
                            div += `<div data-id="${data[i].id}" class="facMenu facMenuActive" onclick="comMenu(${data[i].id})">${data[i].name}</div>`
                        } else {
                            if (i > 8) {
                                div += `<div data-id="${data[i].id}" class="facMenu none" onclick="comMenu(${data[i].id})">${data[i].name}</div>`
                            } else {
                                div += `<div data-id="${data[i].id}" class="facMenu" onclick="comMenu(${data[i].id})">${data[i].name}</div>`
                            }
                        }
                        
                        
                    }
                    list(data[0].id)
                    $('.letTitle').after(div)   
                }
            }
        }); 
    
        $('.facMore').click(function() {
            var menu = $('.menu');
            console.log(menu)
            menu.find('.facMenu').css('display', 'block');
            $(this).remove();
        })
    })
    
    function list(id) {
        $.ajax({
            url: '/api/home/factory',
            type:'get',
            data: {cate: id},
            dataType:'json',
            contentType: "application/json",
            // async: false,
            success: function (result) {
                $('.list').children().remove()
                if (result.code === 200) {
                    var data = result.data
                    var div = '';
                    if (data.length > 0) {
                        for (let i = 0; i < data.length; i++) {
                        div += `<div class="factory toFacHome" onclick="toFacHomeShow(${data[i].id}, ${data[i].uid})" data-id="${data[i].id}" data-uid="${data[i].uid}">
                                    <img src="${MC.pImg(data[i].head)}">
                                    <p>${data[i].com_name}</p>
                                </div>`
                        }
                        $('.list').append(div)
                    } else {
                        var div = '<div class="nullCetner">啊噢，暂时没找到呢</div>'
                        $('.list').append(div)
                    }
                   
                } else {
                    alertMsg(result.msg)
                }
                // var img=new Image();
                // img.src= '';
                // img.onload=function(){
                // }  
            }, err: function(err) {
                alertMsg(err)
            }
        });
    }
    
    function comMenu(id) {
        console.log(id)
        var menu = $('.menu');
        var ids = menu.find(`.facMenu[data-id=${id}]`);
        ids.addClass('facMenuActive')
        ids.siblings('.facMenu').removeClass('facMenuActive')
        list(id)
    } 
    function toFacHomeShow(id, uid) {
        var ids = {
            id: id,
            uid: uid
        }   
        window.location.href = 'facShow.html?uid=' + uid
    }
    </script>
</html>